<?php
/**
 * Created by PhpStorm.
 * User: zhan
 * Date: 2017/11/9  19:27
 */
namespace app\api\logic;
use app\api\BaseModel;

class Index extends  BaseModel{

    /**
     * 关于我们
     */
    public function about(){
        $about = db('about');
        $res = $about->find();
        $res['image']=IMG_PATH.$res['image'];
        $res['content']=htmlspecialchars_decode(str_replace("/ueditor/php/upload",IMG_UED."/ueditor/php/upload",$res['content']));
        return $res;
    }

    /**
     * 轮播图
     */
    public function banner(){
        $banner = db('banner');
        $ban = $banner ->where("status=1")->select();
        foreach($ban as &$v){
            $v['pic']=IMG_PATH.$v['pic'];
        }
        return $ban;
    }
    /**
     * 图文列表
     */
    public function article(){
        $article =db('article')->where("status=1")->order("sort desc,id desc")->select();
        foreach($article as $k=>$v){
            $v['image']=IMG_PATH.$v['image'];
            switch($v['cid']){
                case 0:
                    $list['room'][]=$v;
                    break;
                case 1:
                    $list['drink'][]=$v;
                    break;
                case 2:
                    $list['entertainment'][]=$v;
                    break;
            }
        }
        return $list;
    }
    /**
     * 图文详情
     */
    public function detail(){
        $where['id']=$this->requestData['id'];
        $where['status']=1;
        $article =db('article')->where($where)->find();
        $article['image']=IMG_PATH.$article['image'];
        $article['content'] = str_replace("/ueditor/php/upload",IMG_UED."/ueditor/php/upload",$article['content']);
        return $article;
    }

    /**
     * 首页精品
     */
    public function boutique(){
        $where['status']=1;
        $where['delete']=1;
        //$where['start_date']=strtotime(date("Y-m-d"));
        $package =db('package')->where($where)
            ->field("image,title,id,price")
            ->order("sort desc,id desc")->limit(2)->select();
        foreach($package as &$v){
            $v['image']=IMG_PATH.$v['image'];
        }

        return $package;
    }

    /**
     * 精品推荐
     */
    public function blist()
    {
        $p=isset($this->requestData['page'])?$this->requestData['page']:'1';
        $size=isset($this->requestData['limit'])?$this->requestData['limit']:'10';
        $where['status']=1;
        $where['delete']=1;
       // $where['start_date']=strtotime(date("Y-m-d"));
        $package =db('package')->where($where)
            ->field("image,title,id,price,des,oprice")
            ->order("sort desc,id desc")
            ->page($p,$size)->select();
        foreach($package as &$v){
            $v['image']=IMG_PATH.$v['image'];
            if($v['des']) {
                $v['des'] = unserialize($v['des']);
            }
        }
        $count =db('package')->where($where)
            ->field("image,title,id,price,oprice")
            ->order("sort desc,id desc")
            ->count();
        return array("list"=>$package,'page_num'=>$p,'page_limit'=>$size,'count'=>$count);
    }
    /**
     * 取消规则
     */
    public function rule()
    {
        $list=db("config")->find(1);
        return $list;
    }
    /**
     * 咨询电话
     */
    public function tell()
    {
        $list=db("config")->find(4);
        return $list;
    }
    /**
     * 咨询电话
     */
    public function credit()
    {
        $list=db("config")->find(9);
        return array('bili'=>floatval($list['value']));
    }
}